﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Drawing;

namespace 任务状态
{
    public class RoundedPanel : Panel
    {
        public int CornerRadius { get; set; } = 15; // 圆角半径，默认15

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            // 设置抗锯齿
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            // 创建圆角矩形路径
            GraphicsPath path = new GraphicsPath();
            path.AddArc(0, 0, CornerRadius, CornerRadius, 180, 90); // 左上角
            path.AddArc(this.Width - CornerRadius, 0, CornerRadius, CornerRadius, 270, 90); // 右上角
            path.AddArc(this.Width - CornerRadius, this.Height - CornerRadius, CornerRadius, CornerRadius, 0, 90); // 右下角
            path.AddArc(0, this.Height - CornerRadius, CornerRadius, CornerRadius, 90, 90); // 左下角
            path.CloseFigure();

            // 设置控件的区域为圆角矩形
            this.Region = new Region(path);

            // 填充背景色
            using (SolidBrush brush = new SolidBrush(this.BackColor))
            {
                e.Graphics.FillPath(brush, path);
            }
        }
    }

}
